<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport('joomla.application.component.model');

/**
 * jl_profile jl_profile Model
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */
class JAJobBoardModelJAPaymentconfig extends JModel
{		
	function getVars()
	{
		global $mainframe, $option;
		
		$option_1 = $option.'.japaymentconfig';
		$list = array();
		$list['filter_order']		= $mainframe->getUserStateFromRequest( $option_1.'.filter_order',	'filter_order',	'd.id',	'cmd' );	
		$list['filter_order_Dir'] 	= $mainframe->getUserStateFromRequest( $option_1.'.filter_order_Dir',	'filter_order_Dir',	'',				'word' );
		//$list['limit'] 				= $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
		$list['limit'] 				= $mainframe->getUserStateFromRequest( $option_1.'.limit', 'limit', 5, 'int' );
		
		$list['limitstart'] 		= $mainframe->getUserStateFromRequest( $option_1.'.limitstart', 'limitstart', 0, 'int' );
		$list['search'] 			= $mainframe->getUserStateFromRequest( $option_1.'.search',						'search',			'',	'string' );
		if(!in_array($list['filter_order'], array('d.id', 'd.name', 'd.published'))) $list['filter_order'] = 'd.id';
		return  $list;
	}		
	function total($where='')
	{
		$db=JFactory::getDBO();
		$query=" SELECT COUNT(d.id)FROM #__ja_paymentconfig as d"
		.$where;
		$db->setQuery($query);
		return $db->loadResult();
	}
	function getTypes($where='',$limited='',$order='')
	{
		$db		 =& JFactory::getDBO();
			$query="SELECT 	d.* 
					FROM	#__ja_paymentconfig as d"
					.$where
					.$order
					.$limited;
			$db->setQuery($query);
			$rows=$db->loadObjectList();
			return $rows;		
	}
	function getPayment()
	{
		$payname = JRequest::getVar('pay', '');		
		$db		 =& JFactory::getDBO();
		$query="SELECT 	* 
				FROM	#__ja_paymentconfig"
				." WHERE name='".mysql_escape_string($payname)."'";
		$db->setQuery($query);
		$row = $db->loadObject();
		return $row;			
	}
	function store($obj)
	{
		$db		 =& JFactory::getDBO();
		if($obj->id)
		{
			if($db->updateObject("#__ja_paymentconfig",$obj,'id'))
				return true;
			else {
				return false;
			}
		}
		else 
		{
			if($db->insertObject("#__ja_paymentconfig",$obj))
				return true;
			else {
				return false;			
			}
		}
	}
	function remove($cid)
	{
		$db		 =& JFactory::getDBO();
		if($cid)
		{
			$query=" DELETE FROM #__ja_paymentconfig WHERE id in(".$cid.")";
			$db->setQuery($query);
			if($db->query())
				return true;
		}
		return false;
	}
	function published($published)
	{		
		$db		 =& JFactory::getDBO();
		$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
		$cids = implode( ',', $cid );
				
		$query="update #__ja_paymentconfig as d set d.published=".$published." where d.id in(".$cids.")";
		$db->setQuery($query);
		if($db->query())
		{
			return true;
		}
		else {
			return false;
		}
	}
	
	function check_exist_payment_file($rows)
	{
		for ($i=0;$i<count($rows);$i++)
		{
			$row = $rows[$i];
			$desk = JPATH_COMPONENT_SITE.DS.'asset'.DS.'payments'.DS.$row->name.'.php';
			if (!file_exists($desk))
			{
				$rows[$i]->error = 1;
				$rows[$i]->error_msg = '';
				$rows[$i]->error_msg = '<font color="Red"> '.JText::_("Your payment file ")."'".$row->name.".php'".JText::_(" is not exist now.");
				$rows[$i]->error_msg .= JText::_("You can download this file from ").'<a target="_blank" href="http://www.joomlart.com/forums/downloads.php?do=file&id=865">http://www.joomlart.com/forums/downloads.php?do=file&id=865</a>.';
				$rows[$i]->error_msg .= JText::_("Then copy to ").JPATH_COMPONENT_SITE.DS.'assets'.DS.'payments';
				$rows[$i]->error_msg .= ' </font>';
				
			}
			else 
			{
				$rows[$i]->error = 0;
			}
		}
		return $rows;
	}
	
	
}
?>